package com.ddd.domain.user.service.impl;

import com.ddd.domain.user.dto.UserDto;
import com.ddd.domain.user.entity.UserDo;
import com.ddd.domain.user.event.UserEvent;
import com.ddd.domain.user.repository.UserDao;
import com.ddd.domain.user.service.UserService;
import com.ddd.infrastructure.utils.BeanCopierUtil;
import com.ddd.infrastructure.utils.SnowIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
   private UserDao userDao;
    @Autowired
    private  UserEvent userEvent;

    @Override
    public List<UserDto> getUserAll() {
        List<UserDo> userAll = userDao.getUserAll();
        return BeanCopierUtil.copylist(userAll,UserDto.class);
    }

    @Override
    public String addByUser(UserDo userDo) {
        String s = SnowIdUtils.uniqueLongHex();
        userDo.setUserId(s);
        userEvent.ageGreater18(userDo);
        userDao.addByUser(userDo);
        return  s;
    }

}
